#region Using Statements
using Microsoft.Xna.Framework;
using GameVuTru.ManagerScreens;
using GameVuTru.ResourceManager;
using Microsoft.Xna.Framework.Media;
using GameVuTru.GameObject;
#endregion


namespace GameVuTru.Screens
{
    class MainMenuScreen : MenuScreen
    {
        #region Initialization


        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public MainMenuScreen()
            : base("Main Menu")
        {
            // Create our menu entries.
            MenuEntry playGameMenuEntry = new MenuEntry(ReSouce.PlayButton, new Vector2(280, 150));
            MenuEntry ResumeMenuEntry = new MenuEntry(ReSouce.ResumeButton, new Vector2(280, 200));
            MenuEntry optionsMenuEntry = new MenuEntry(ReSouce.OptionButton, new Vector2(280, 250));
            MenuEntry aboutMenuEntry = new MenuEntry(ReSouce.AboutButton, new Vector2(280, 300));
            MenuEntry exitMenuEntry = new MenuEntry(ReSouce.exitButton, new Vector2(280, 350));
            // System.Console.Write(ReSouce.phithuyen.Width);
            // Hook up menu event handlers.
            playGameMenuEntry.Selected += PlayGameMenuEntrySelected;
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
            ResumeMenuEntry.Selected += ResumeMenuEntrySelected;
            aboutMenuEntry.Selected += aboutMenuEntrySelected;
            exitMenuEntry.Selected += exitMenuEntrySelected;

            // Add entries to the menu.
            MenuEntries.Add(playGameMenuEntry);
            MenuEntries.Add(ResumeMenuEntry);
            MenuEntries.Add(optionsMenuEntry);
            MenuEntries.Add(aboutMenuEntry);
            MenuEntries.Add(exitMenuEntry);   

            //nhac nen menu
            if (ManagerSound.soundOn)
            {
                ManagerSound.PlaySong(ReSouce.soundMenu);
            }
            if (!ManagerSound.soundOn)
            {
                ManagerSound.StopSong();
            }

        }
                #endregion

        #region Handle Input
        void PlayGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            //khoi tao lai cac bjen khj bat dau choi
            CreateLevel.level = 1;
            GameplayScreen.life = 3;
            GameplayScreen.Phao = 3;
            GameplayScreen.numcoin = 0;
            GameplayScreen.numScore = 0;
            Player.bullettype = BULLETTYPE.BULLETBLUE;
            Player.PowerBullet = 1;
            ScreenManager.RemoveScreen(this);
            LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
                               new GameplayScreen());
            ManagerSound.StopSong();
            if (ManagerSound.soundOn)
            {
                ManagerSound.PlaySound(ReSouce.soundTap);
            }
        }
        void ResumeMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            if (GameplayScreen.life > 0 && GameplayScreen.ContinueGame)
            {
                ScreenManager.RemoveScreen(this);
                ManagerSound.StopSong();
                if (ManagerSound.soundOn)
                {
                    ManagerSound.PlaySound(ReSouce.soundTap);
                }
                ScreenManager.AddScreen(new GameplayScreen(GameplayScreen.staticPlayer, CreateLevel.listenemy, GameplayScreen.ListBulletEnemy, GameplayScreen.ListBonus), null);
            }

        }
        void aboutMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            if (ManagerSound.soundOn)
            {
                ManagerSound.PlaySound(ReSouce.soundTap);
            }
            ScreenManager.RemoveScreen(this);
            ScreenManager.AddScreen(new About(), null);

        }

        void OptionsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            if (ManagerSound.soundOn)
            {
                ManagerSound.PlaySound(ReSouce.soundTap);
            }
            ScreenManager.RemoveScreen(this);
            ScreenManager.AddScreen(new OptionsMenuScreen(), e.PlayerIndex);
        }

        void exitMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            if (ManagerSound.soundOn)
            {
                ManagerSound.PlaySound(ReSouce.soundTap);
            }
         //   ScreenManager.RemoveScreen(this);
            ScreenManager.Game.Exit();
        }

        protected override void OnCancel(PlayerIndex playerIndex)
        {
            ScreenManager.Game.Exit();
        }


        #endregion
    }
}
